package yyy.ab.modules.system.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import yyy.ab.common.core.BaseServiceImpl;
import yyy.ab.common.core.Query;
import yyy.ab.common.utils.StringUtils;
import yyy.ab.modules.system.entity.SysDictDetail;
import yyy.ab.modules.system.mapper.SysDictDetailMapper;
import yyy.ab.modules.system.service.SysDictDetailService;

import java.util.Map;

@Service
@RequiredArgsConstructor
public class SysDictDetailServiceImpl extends BaseServiceImpl<SysDictDetailMapper, SysDictDetail> implements SysDictDetailService {

    @Override
    public IPage<SysDictDetail> findPage(Map<String, Object> params) {
        Long dictId = null;
        if (params.containsKey("dictId")) {
            dictId = Long.valueOf(params.get("dictId").toString());
        }
        Page<SysDictDetail> page = new Query<SysDictDetail>(params).getPage();
        QueryWrapper<SysDictDetail> detailQueryWrapper = new QueryWrapper<>();
        detailQueryWrapper.eq(dictId != null, "dict_id", dictId);
        detailQueryWrapper.orderByAsc("sort");
        return baseMapper.selectPage(page, detailQueryWrapper);
    }
}
